/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package arbitration.gui;

import arbitration.logic.CalcUtils;
import arbitration.logic.validator.CountValidator;
import arbitration.logic.validator.DateValidator;
import com.toedter.calendar.HolidayPolicy;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.Date;
import javax.swing.JTextField;

/**
 *
 * @author prophet
 */
public class PaymentPeriodListener implements FocusListener{
    private CalcPanel calcPanel;
    private CountValidator countValidator;
    private HolidayPolicy holidayPolicy;

    public PaymentPeriodListener(CalcPanel calcPanel){
        this.calcPanel=calcPanel;
        this.countValidator=new CountValidator();        
    }

    public void focusGained(FocusEvent e) {        
    }

    public void focusLost(FocusEvent e) {
        Date deliveryDate=calcPanel.getDeliveryDate().getDate();
        Integer days=(Integer)countValidator.isValid(calcPanel.getPaymentDays().getText());
        if(deliveryDate!=null&&days!=null){
                calcPanel.getPaymentPeriod().setText(
                        CalcUtils.dateToString(CalcUtils.getPaymentEndDate(deliveryDate, days,holidayPolicy)));
        }
    }

    public CalcPanel getCalcPanel() {
        return calcPanel;
    }

    public void setCalcPanel(CalcPanel calcPanel) {
        this.calcPanel = calcPanel;
    }

    public HolidayPolicy getHolidayPolicy() {
        return holidayPolicy;
    }

    public void setHolidayPolicy(HolidayPolicy holidayPolicy) {
        this.holidayPolicy = holidayPolicy;
    }

    
}
